import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:grint/constant/colors.dart';
import 'package:grint/widget/my_text.dart';

class PopTool {
  static void tanChuTongYongKuang(
    String touBiao,
    String neiRongKuai, {
    String fouDingCi = "Cancel",
    String kenDingCi = "Confirm",
    VoidCallback? guanBiHuiDiao,
    VoidCallback? queRenHuiDiao,
    bool biaoShiZhuangTai = false,
  }) {
    SmartDialog.show(
      backDismiss: false,
      clickMaskDismiss: false,
      animationType: SmartAnimationType.scale,
      builder:
          (_) => NamedBox(
            touBiao: touBiao,
            neiRongKuai: neiRongKuai,
            fouDingCi: fouDingCi,
            kenDingCi: kenDingCi,
            guanBiHuiDiao: guanBiHuiDiao,
            queRenHuiDiao: queRenHuiDiao,
            biaoShiZhuangTai: biaoShiZhuangTai,
          ),
    );
  }
}

class NamedBox extends StatelessWidget {
  final String touBiao;
  final String neiRongKuai;
  final String fouDingCi;
  final String kenDingCi;
  final VoidCallback? guanBiHuiDiao;
  final VoidCallback? queRenHuiDiao;
  final bool biaoShiZhuangTai;

  const NamedBox({
    Key? key,
    required this.touBiao,
    required this.neiRongKuai,
    this.fouDingCi = "Cancel",
    this.kenDingCi = "Confirm",
    this.guanBiHuiDiao,
    this.queRenHuiDiao,
    this.biaoShiZhuangTai = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 320.w,
      padding: EdgeInsets.all(20.w),
      decoration: BoxDecoration(
        color: AppColors.white,
        borderRadius: BorderRadius.circular(16.r),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          MyText(
            text: touBiao,
            type: TextType.rubik,
            fontSize: 18.sp,
            color: AppColors.black,
            fontWeight: FontWeight.bold,
            textAlign: TextAlign.center,
          ),
          SizedBox(height: 15.h),

          MyText(
            text: neiRongKuai,
            type: TextType.miSans,
            fontSize: 14.sp,
            color: AppColors.textGrey,
            maxLines: 5,
            overflow: TextOverflow.ellipsis,
            textAlign: TextAlign.center,
          ),
          SizedBox(height: 25.h),

          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              GestureDetector(
                onTap: () {
                  SmartDialog.dismiss();
                  guanBiHuiDiao?.call();
                },
                child: Container(
                  width: 120.w,
                  height: 40.h,
                  decoration: BoxDecoration(
                    border: Border.all(color: AppColors.textGrey),
                    borderRadius: BorderRadius.circular(20.r),
                  ),
                  alignment: Alignment.center,
                  child: MyText(
                    text: fouDingCi,
                    type: TextType.miSans,
                    fontSize: 14.sp,
                    color: AppColors.textGrey,
                  ),
                ),
              ),

              GestureDetector(
                onTap:
                    biaoShiZhuangTai
                        ? null
                        : () {
                          SmartDialog.dismiss();
                          queRenHuiDiao?.call();
                        },
                child: Container(
                  width: 120.w,
                  height: 40.h,
                  decoration: BoxDecoration(
                    color: AppColors.icon,
                    borderRadius: BorderRadius.circular(20.r),
                  ),
                  alignment: Alignment.center,
                  child:
                      biaoShiZhuangTai
                          ? SizedBox(
                            width: 20.w,
                            height: 20.w,
                            child: const CircularProgressIndicator(
                              strokeWidth: 2,
                              color: AppColors.white,
                            ),
                          )
                          : MyText(
                            text: kenDingCi,
                            type: TextType.miSans,
                            fontSize: 14.sp,
                            color: AppColors.white,
                          ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
